from llm.TextScoreBert import TextScoreBert


class ScorerPart6:
    ANS_PARA_PART_6 = f"本实验实现了反相器。当输入端为高电平时，输出端会输出低电平，反之则会输出高电平，实现逻辑上的取反操作。"

    def __init__(self):
        self.bert = TextScoreBert("files/config.inf")

    # 报告判分: 第六部分
    def score_part_6(self, dict_matched_paragraphs, list_matched_images):
        score = 0
        ssim = 0
        try:
            for para in dict_matched_paragraphs["6实验结果分析"]["word"]:
                similar_val = self.bert.similar_text(self.ANS_PARA_PART_6, para)
                if similar_val is not None and similar_val > 0.5:
                    score = 1
                    ssim = similar_val
                    print("part 6: 得分, similar_val:", similar_val, ", para:", para)
                    break
        except Exception as e:
            print(f"第6部分判分出错: {e}")
        return score, ssim